﻿@using System.Text.RegularExpressions
@inherits PageBase

<BInput Type="InputType.Text" TValue="string" Size="@InputSize.Small" @bind-Value="@SearchText"
        Style="width:220px;margin-left: -100px;display:inline-block;" EnableAlwaysRender="true" EnableClearButton="true"></BInput>
<BButton Type="@ButtonType.Text" Size="@ButtonSize.Medium" Icon="el-icon-search" OnClick="e=>Search()"
         Style="padding: 0px 0px !important;display: inline-block;color:#67C23A;margin:0px 10px 0px 10px !important"></BButton>
<BButton Type="@ButtonType.Success" OnClick="e=>NewTopic()" IsPlain="true" Size="@ButtonSize.Small"> 发表新帖 </BButton>

@code   {
    internal string SearchText { get; set; }
    internal string SpecialCharacter = "@_~$%^*+#￥&=";

    internal void Search()
    {
        if (string.IsNullOrWhiteSpace(SearchText))
            return;
        SearchText = RemoveSpecialCharacter(SearchText);
        NavigationManager.NavigateTo($"search/{SearchText}",true);
    }

    /// <summary>
    /// 去掉特殊字符
    /// </summary>
    /// <param name="hexData"></param>
    /// <returns></returns>
    string RemoveSpecialCharacter(string hexData)
    {
        return Regex.Replace(hexData, "[ \\[ \\] \\^ \\-_*×――(^)|'$%~!@#$…&%￥—+=<>《》!！??？:：•`·、。，；,.;\"‘’“”-]", "");
    }
    internal void NewTopic() => NavigationManager.NavigateTo("/topic/new");
}